package org.luxor.generator.config;

import org.apache.commons.lang.StringUtils;
import org.luxor.generator.entity.ProjectModel;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局参数配置
 *
 * @author Mark sunlightcs@gmail.com
 */
@ConfigurationProperties(prefix = GeneratorPropertie.PREFIX)
public class GeneratorPropertie {
    public static final String PREFIX = "generator";

    private static Map<String, String> DEF_MAPPINGS = new HashMap<>();
    private static ProjectModel DEF_PROJECT_MODEL = new ProjectModel(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, "org.luxor.commons", "org.luxor", "example",false,false);

    static {
        DEF_MAPPINGS.put("tinyint", "Byte");
        DEF_MAPPINGS.put("smallint", "Short");
        DEF_MAPPINGS.put("mediumint", "Integer");
        DEF_MAPPINGS.put("int", "Integer");
        DEF_MAPPINGS.put("integer", "Integer");
        DEF_MAPPINGS.put("bigint", "Long");
        DEF_MAPPINGS.put("float", "Float");
        DEF_MAPPINGS.put("double", "DoubleR");
        DEF_MAPPINGS.put("decimal", "BigDecimal");
        DEF_MAPPINGS.put("bit", "Boolean");
        DEF_MAPPINGS.put("char", "String");
        DEF_MAPPINGS.put("varchar", "String");
        DEF_MAPPINGS.put("tinytext", "String");
        DEF_MAPPINGS.put("text", "String");
        DEF_MAPPINGS.put("mediumtext", "String");
        DEF_MAPPINGS.put("longtext", "String");
        DEF_MAPPINGS.put("date", "Date");
        DEF_MAPPINGS.put("datetime", "Date");
        DEF_MAPPINGS.put("timestamp", "Date");
        DEF_MAPPINGS.put("NUMBER", "Integer");
        DEF_MAPPINGS.put("INT", "Integer");
        DEF_MAPPINGS.put("INTEGER", "Integer");
        DEF_MAPPINGS.put("BINARY_INTEGER", "Integer");
        DEF_MAPPINGS.put("LONG", "String");
        DEF_MAPPINGS.put("FLOAT", "Float");
        DEF_MAPPINGS.put("BINARY_FLOAT", "Float");
        DEF_MAPPINGS.put("DOUBLE", "Double");
        DEF_MAPPINGS.put("BINARY_DOUBLE", "Double");
        DEF_MAPPINGS.put("DECIMAL", "BigDecimal");
        DEF_MAPPINGS.put("CHAR", "String");
        DEF_MAPPINGS.put("VARCHAR", "String");
        DEF_MAPPINGS.put("VARCHAR2", "String");
        DEF_MAPPINGS.put("NVARCHAR", "String");
        DEF_MAPPINGS.put("NVARCHAR2", "String");
        DEF_MAPPINGS.put("CLOB", "String");
        DEF_MAPPINGS.put("BLOB", "String");
        DEF_MAPPINGS.put("DATE", "Date");
        DEF_MAPPINGS.put("DATETIME", "Date");
        DEF_MAPPINGS.put("TIMESTAMP", "Date");
        DEF_MAPPINGS.put("TIMESTAMP(6)", "Date");
        DEF_MAPPINGS.put("int8", "Long");
        DEF_MAPPINGS.put("int4", "Integer");
        DEF_MAPPINGS.put("int2", "Short");
        DEF_MAPPINGS.put("numeric", "BigDecimal");
    }

    @NestedConfigurationProperty
    private ProjectModel projectModel;

    /**
     * 数据库列的数据类型 -> Java类型之间的对应关系
     */
    private Map<String, String> typeMappings;

    public GeneratorPropertie() {
        this.projectModel = DEF_PROJECT_MODEL;
        this.typeMappings = DEF_MAPPINGS;
    }

    public ProjectModel getProjectModel() {
        return projectModel;
    }

    public void setProjectModel(ProjectModel projectModel) {
        this.projectModel = projectModel;
    }

    public Map<String, String> getTypeMappings() {
        return typeMappings;
    }

    public void setTypeMappings(Map<String, String> typeMappings) {
        this.typeMappings = typeMappings;
    }
}
